# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=soundtouch
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.3.3
pkgrel=1
pkgdesc="An audio processing library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.surina.net/soundtouch/"
msys2_references=(
  "cpe: cpe:/a:surina:soundtouch"
)
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=(https://www.surina.net/${_realname}/${_realname}-${pkgver}.tar.gz
        0001-no-undefined-on.mingw.patch
        0003-fix-docdir.mingw.patch
        0004-missing-municode.patch)
noextract=(${_realname}-${pkgver}.tar.gz)
sha256sums=('43b23dfac2f64a3aff55d64be096ffc7b73842c3f5665caff44975633a975a99'
            '76b3041e952675e56138461c5fa8a5abacac31380ce90b27038d0deac46f91be'
            '2cd136046831f3ad9a2e37c0afe3ecd9f25ce27f5dbf4ee8b23b862a96e76cd5'
            '876b8bc6ba99b35b0b13fe963aacf9c7f82a8c7c53b9e8c678aee9af7607c15f')

prepare() {
  bsdtar -xf ${_realname}-${pkgver}.tar.gz || true

  cd "${srcdir}/${_realname}"
  patch -p1 -i "${srcdir}"/0001-no-undefined-on.mingw.patch
  patch -p1 -i "${srcdir}"/0003-fix-docdir.mingw.patch
  patch -p1 -i "${srcdir}"/0004-missing-municode.patch

  ./bootstrap
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_realname}/COPYING.TXT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.TXT"
}
